package com.pxst.fi.controller;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.pxst.exception.BusinessException;
import com.pxst.fi.entity.FiExcelModel;
import com.pxst.fi.req.FiOrderReq;
import com.pxst.fi.resp.FiOrderResp;
import com.pxst.resp.PageResp;
import com.pxst.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.pxst.fi.req.FiCreateOrderReq;
import com.pxst.fi.service.FiService;
import com.pxst.resp.ApiResp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.IOException;
import java.util.List;

/** 
* @author yangxy
* @version 创建时间：2023年9月7日 下午2:46:33 
*/
@RestController
@RequestMapping("/fi")
@Api(tags = "充值相关接口")
@Validated
public class FiController {
	@Autowired
	private FiService fiService;
	
	@PostMapping("/createOrder")
	@ApiOperation(value = "创建fi订单")
	public ApiResp<String> createOrder(@RequestBody FiCreateOrderReq fiCreateOrderReq){
		return fiService.createOrder(fiCreateOrderReq);
	}

	@GetMapping("/getOrder")
	@ApiOperation("查询充值订单数据")
	public ApiResp<PageResp<FiOrderResp>> getAllByCondition(FiOrderReq fiOrderReq){
		return fiService.getAllByCondition(fiOrderReq);
	}

	@GetMapping("/download")
	@ApiOperation("汇出报表")
	public void download(FiOrderReq fiOrderReq, HttpServletResponse response){
		List<FiExcelModel> fiExcelModels = fiService.download(fiOrderReq);
		try {
			ExcelUtils.exportExcel(fiExcelModels, "充值汇出报表", "充值报表", FiExcelModel.class, "FI-", response);
		} catch (IOException e) {
			e.printStackTrace();
			throw new BusinessException("汇出报表错误");
		}
	}
}
